<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="../../resource/css/reset.css"/>
        <link type="text/css" rel="stylesheet" href="../../resource/css/api_index.css"/>
        <script type="text/javascript" src="../../resource/js/fw/jquery-1.8.3.min.js"></script>
    </head>
    <body>
        <div class="pk-wrap">

            <div class="pk-unit-wrap">
                <div class="pk-unit">
                    <h1 class="clearfix">
                        <span class="pk-color-title">Function.apply()</span>
                        <span class="pk-float-right pk-tip">Core > Object > Function > apply</span>
                    </h1>
                </div>
                <div class="pk-unit">
                    <div class="pk-unit-with-style">
                        <div class="pk-unit-tag">Description</div>
                        <pre>    语法：
        function.apply(thisobj, args)

    apply()将指定的函数function作为对象thisobj的方法来调用，并传入在args数组中包含的参数。它返回的是调用function的返回值。在函数体内，关键字this指代thisobj对象。
    args参数必须是数组或Arguments对象。如果想单独指定传递给函数的参数，而不是通过数组元素来指定参数，可以使用Function.call()方法。
    
    异常：
        如果调用该函数的对象不是函数，或者参数args不是数组和Arguments对象，则抛出该异常。</pre>
                    </div>
                </div>
            </div>

                        <div class="pk-unit-wrap">
                <div class="pk-unit">
                    <h1 class="clearfix">
                        <span class="pk-color-title pk-italic">参数 function.apply(thisobj, args)</span>
                    </h1>
                </div>
                <div class="pk-unit">
                    <table>
                        <thead>
                            <tr>
                                <th class="pk-w120">参数名</th>
                                <th>描述</th>
                            </tr>
                        </thead>
                        <tbody>
                                                        <tr>
                                <td>thisobj</td>
                                <td>调用function的对象。在函数体中，thisobj是关键字this的值。如果这个参数为null，则使用全局对象。</td>
                            </tr>
                                                        <tr>
                                <td>args</td>
                                <td>一个值数组。它的元素是传递给function的参数值。</td>
                            </tr>
                                                    </tbody>
                    </table>
                </div>
            </div>
            
                        <div class="pk-unit-wrap">
                <div class="pk-unit">
                    <h1 class="clearfix">
                        <span class="pk-color-title pk-italic">返回值</span>
                    </h1>
                </div>
                <div class="pk-unit">
                    <div class="pk-unit-with-style">
                        <div class="pk-unit-tag">Description</div>
                        <pre>调用函数function的返回值。</pre>
                    </div>
                </div>
            </div>
            
            
            
                        <div class="pk-unit-wrap">
                <div class="pk-unit">
                    <h1 class="clearfix">
                        <span class="pk-color-title pk-italic">代码示例</span>
                    </h1>
                </div>
                <div class="pk-unit">
                    <div class="pk-unit-with-style pk-code">
                        <div class="pk-unit-tag">
                            <span>Code</span>
                        </div>
                        <div class="pk-unit-fns">
                            <a href="javascript:" title="Fold or unfold the code" data-rel="fold-btn">-Fold</a>
                            <a href="javascript:" data-rel="copy-code">Copy</a>
                        </div>
                        <pre>// 将默认的Object.toString()应用在一个对象上，
// 以便覆盖该对象上的toString()方法。注意没传参数
Object.prototype.toString.apply(o);
// 用apply()调用blath.max()方法来查找数组中的最大元素
// 注意在这种情况下，第一个参数无所谓
<span class="pk-code-key">var</span> data = [1,2,3,4,5,6,7,8];
Max.max.apply(null, data);</pre>
                    </div>
                </div>
            </div>

            <script type="text/javascript" src="../../resource/js/fw/clipboard/ZeroClipboard.min.js"></script>
            <script type="text/javascript" src="../../resource/js/api_index.js"></script>
            <script type="text/javascript">
                if(window.clipboardData){
                    $('a[data-rel="copy-code"]').click(function(){
                        window.clipboardData.setData('text',$(this).parent().next().text());
                        alert("Copy successfully!");
                    });
                }else{
                    clipboard($('a[data-rel="copy-code"]'),"../../resource/js/fw/clipboard/ZeroClipboard.swf");
                }
            </script>
                    </div>
    </body>
</html>
